﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfApp1Demo.Model;

namespace WpfApp1Demo.DB
{
    public class LocalDB
    {
        //sqlstring 为数据库右击的属性连接字符串的值
        static string sqlString = "Data source=172.20.236.2;Initial Catalog=Wangzhibin;Persist Security Info=True;User ID=sa;Password=infocore";
        
        
        public DataSet ToGetDatas(string Sql)
        {
            using (SqlConnection Conn  = new SqlConnection(sqlString))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(Sql, Conn))
                {
                    DataSet ds = new DataSet();
                    Conn.Open();
                    da.Fill(ds);
                    da.Dispose();
                    return ds;
                }
            }
        }

        internal List<User> GetUser(string name)
        {
            try
            {
                return Users.Where(x => x.User_name.Contains(name)).ToList();
            }
            catch (Exception)
            {
                throw new NotImplementedException();
            }
            
        }
        public List<User> Users { get; set; }

    }

    //https://blog.csdn.net/weixin_44003632/article/details/86637817
    //public class Class1
    //{
    //    public List<Model.Class1> MyList(string where)
    //    {
    //        DataSet ds = DB.ToGetData("select *from Test " + where);
    //        if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
    //        {
    //            Model.Class1 MyClass1 = null;
    //            List<Model.Class1> MyList = new List<Model.Class1>();
    //            foreach (DataRow item in ds.Tables[0].Rows)
    //            {
    //                MyClass1 = new Model.Class1();
    //                MyClass1.username = item["username"].ToString();
    //                MyClass1.userpwd = item["userpwd"].ToString();
    //                MyList.Add(MyClass1);

    //            }
    //            return MyList;
    //        }
    //        else
    //        {
    //            return null;
    //        }
    //    }

    //}
}
